<RapidHardware>
	<ExternalBusInput Name="EQI" Width="64" />
	<ExternalBusOutput Name="EQO" Width="42" />
	<!-- Registers and Operators -->
	<Register Name="A" Width="32" />
	<Register Name="B" Width="32" />
	<ALU Name="ADD" Width="32" Type="Add" />
	<ALU Name="AND" Width="32" Type="AndMask" />
	<!-- Equality Bit -->
	<Register Name="SR" Width="1" />
	<LogicBlock Name="EQ" Expression="IN1{32} = IN2{32}"/>
	<Join From="EQ.OUT" To="SR.IN" />
	<StatusOutput Name="EQ" From="SR.OUT" />
	<!-- Stack -->
	<RAM Name="STACK" Width="32" Depth="12" />
	<Register Name="SP" Width="6" />
	<ALU Name="SP_INC" Width="6" Type="INC" />
	<ALU Name="SP_DEC" Width="6" Type="DEC" />
	<Join From="SP.OUT" To="STACK.ADDRESS" />
	<Join From="SP.OUT" To="SP_INC.IN1" />
	<Join From="SP.OUT" To="SP_DEC.IN1" />


	<!-- Basic Constants -->
	<Constant Name="ZERO" Value="0" Width="32" />
	<Constant Name="ZERO_BIT" Value="0" Width="1" />
	<Constant Name="ONE_BIT" Value="1" Width="1" />

	<!-- External FIFO Interface -->
	<Register Name="QI" Width="32" />
	<Register Name="QT" Width="6" />
	<Register Name="QO" Width="32" />
	
	<BitCombine Name="E_OUT" InputWidths="32,2,6,1,1" />
	<Join From="E_OUT.OUT" To="EQO.IN" />
	<Join From="QO.OUT" To="E_OUT.IN1" />
	<Join From="ZERO.OUT" To="E_OUT.IN2" />
	<Join From="ZERO.OUT" To="E_OUT.IN3" />
	<Join From="ZERO_BIT.OUT" To="E_OUT.IN4" />

	<BitBreakout Name="E_IN" OutputWidths="32,24,6,1,1" />
	<Join From="EQI.OUT" To="E_IN.IN" />
	<Join From="E_IN.OUT1" To="QI.IN" />
	<Join From="E_IN.OUT3" To="QT.IN" />

	<Resize Name="QT_32" InputWidth="6" OutputWidth="32" />
	<Join From="QT.OUT" To="QT_32.IN" />
	
	<!-- Program Support -->
	<ProgramROMRAM  Name="PROG" ConstantWidth="32" RAMOffset="100" RAMDepth="50" ROMProgramPath="c:\src\rapidhdl\extras\quick_rom.rasm" RAMProgramPath="c:\src\rapidhdl\extras\quick_ram.rasm" ConstantRegister = "C" ProgramCounter = "PC">
		<MicroCore Name="CORE">
				<OpCode Name="JMP_EQI">
						<Branch Status="EQI_READY" ToLabel="EQI_READY" />
						<Jump ToLabel="EQI_NOT_READY" />
						<State ControlState="PC_JUMP" Label="EQI_READY" />
						<State ControlState="NOP" Label="EQI_NOT_READY" />
						<State ControlState="NOP"/>
						<State ControlState="NOP"/>
				</OpCode>


				<OpCode Name="BEQ">
						<Branch Status="EQ" ToLabel="JMP_0_EQ" />
						<Jump ToLabel="JMP_0_DONE" />
						<State ControlState="PC_JUMP" Label="JMP_0_EQ" />
						<State ControlState="NOP" Label="JMP_0_DONE" />
				</OpCode>

				<OpCode Name="JMP">
						<State ControlState="PC_JUMP" />
						<State ControlState="NOP" />
						<State ControlState="NOP" />
						<State ControlState="NOP" />
				</OpCode>

				<OpCode Name="PUSH_A">
						<State ControlState="PUSH_A" />
						<State ControlState="SP_INC" />
				</OpCode>
						
				<OpCode Name="PULL_A">
						<State ControlState="SP_DEC" />
						<State ControlState="NOP" />
						<State ControlState="NOP" />
						<State ControlState="PULL_A" />
				</OpCode>

				<OpCode Name="PUSH_B">
						<State ControlState="PUSH_B" />
						<State ControlState="SP_INC" />
				</OpCode>
						
				<OpCode Name="PULL_B">
						<State ControlState="SP_DEC" />
						<State ControlState="NOP" />
						<State ControlState="NOP" />
						<State ControlState="PULL_B" />
				</OpCode>

				<OpCode Name="PROGRAM">
						<State ControlState="PROGRAM" />
						<State ControlState="PROGRAM" />
						<State ControlState="PROGRAM" />
				</OpCode>

				<!-- NOP -->
				<ControlState Name="NOP" OpCode="true" />	
				<!-- LOAD_A_C -->
				<ControlState Name="LOAD_A_C" OpCode="true" >
					<Join From="C.OUT" To="A.IN" />
					<Activate Signal="A.LATCH" />
				</ControlState>
				<!-- LOAD_B_C -->
				<ControlState Name="LOAD_B_C" OpCode="true" >
					<Join From="C.OUT" To="B.IN" />
					<Activate Signal="B.LATCH" />
				</ControlState>
				<!-- PUSH_A -->
				<ControlState Name="PUSH_A">
					<Join From="A.OUT" To="STACK.DATA_IN" />
					<Activate Signal="STACK.WRITE" />
				</ControlState>
				<!-- PULL_A -->
				<ControlState Name="PULL_A">
					<Join From="STACK.DATA_OUT" To="A.IN" />
					<Activate Signal="A.LATCH" />
				</ControlState>
				<!-- PUSH_B -->
				<ControlState Name="PUSH_B">
					<Join From="B.OUT" To="STACK.DATA_IN" />
					<Activate Signal="STACK.WRITE" />
				</ControlState>
				<!-- PULL_B -->
				<ControlState Name="PULL_B">
					<Join From="STACK.DATA_OUT" To="B.IN" />
					<Activate Signal="B.LATCH" />
				</ControlState>
				<!-- LOAD_A_QI -->
				<ControlState Name="LOAD_A_QI"  OpCode="true" >
					<Join From="QI.OUT" To="A.IN" />
					<Activate Signal="A.LATCH" />
				</ControlState>
				<!-- LOAD_QO_A -->
				<ControlState Name="LOAD_QO_A"  OpCode="true" >
					<Join From="A.OUT" To="QO.IN" />
					<Activate Signal="QO.LATCH" />
				</ControlState>
				<!-- PC_INC -->
				<ControlState Name="PC_INC">
					<Join From="PC_INC.OUT" To="PC.IN" />
					<Activate Signal="PC.LATCH" />
					<Activate Signal="C.LATCH" />
				</ControlState>
				<!-- PC_JUMP -->
				<ControlState Name="PC_JUMP">
					<Join From="C.OUT" To="PC.IN" />
					<Activate Signal="PC.LATCH" />
				</ControlState>
				<!-- EQI_READ -->
				<ControlState Name="EQI_READ"  OpCode="true" >
					<Activate Signal="QI.LATCH" />
					<Activate Signal="QT.LATCH" />
					<Activate Signal="EQI.READ" />
				</ControlState>
				<!-- COMP_A_C -->
				<ControlState Name="COMP_A_C" OpCode="true" >
					<Join From="A.OUT" To="EQ.IN1" />
					<Join From="C.OUT" To="EQ.IN2" />
					<Activate Signal="SR.LATCH" />
				</ControlState>
				<!-- COMP_A_B -->
				<ControlState Name="COMP_A_B"  OpCode="true" >
					<Join From="A.OUT" To="EQ.IN1" />
					<Join From="B.OUT" To="EQ.IN2" />
					<Activate Signal="SR.LATCH" />
				</ControlState>
				<!-- ADD_A_C -->
				<ControlState Name="ADD_A_C"  OpCode="true" >
					<Join From="A.OUT" To="ADD.IN1" />
					<Join From="C.OUT" To="ADD.IN2" />
					<Join From="ADD.OUT" To="A.IN" />
					<Activate Signal="A.LATCH" />
				</ControlState>
				<!-- ADD_A_B -->
				<ControlState Name="ADD_A_B"  OpCode="true" >
					<Join From="A.OUT" To="ADD.IN1" />
					<Join From="B.OUT" To="ADD.IN2" />
					<Join From="ADD.OUT" To="A.IN" />
					<Activate Signal="A.LATCH" />
				</ControlState>
				<!-- EQO_POST -->
				<ControlState Name="EQO_POST"  OpCode="true" >
					<Activate Signal="EQO.LATCH" />
				</ControlState>
				<!-- SP_INC -->
				<ControlState Name="SP_INC">
					<Join From="SP_INC.OUT" To="SP.IN" />
					<Activate Signal="SP.LATCH" />
				</ControlState>
				<!-- SP_DEC -->
				<ControlState Name="SP_DEC">
					<Join From="SP_DEC.OUT" To="SP.IN" />
					<Activate Signal="SP.LATCH" />
				</ControlState>
				<!-- A_AND_B -->
				<ControlState Name="A_AND_B">
					<Join From="A.OUT" To="AND.IN1" />
					<Join From="B.OUT" To="AND.IN2" />
					<Activate Signal="A.LATCH" />
				</ControlState>
				<!-- PROGRAM -->
				<ControlState Name="PROGRAM">
					<Activate Signal="PROG.PROGRAM" />
				</ControlState>
				<!-- COMP_QT_C -->
				<ControlState Name="COMP_QT_C"  OpCode="true" >
					<Join From="QT_32.OUT" To="EQ.IN1" />
					<Join From="C.OUT" To="EQ.IN2" />
					<Activate Signal="SR.LATCH" />
				</ControlState>

		</MicroCore>
	</ProgramROMRAM>	


	<Join From="A.OUT" To="PROG.IR" />
	<Join From="B.OUT" To="PROG.CONST" />
	<Join From="QI.OUT" To="PROG.ADDRESS" />

</RapidHardware>